HW 06: hmc 4.0

Add functions to your x86-64 compiler.

Goals

The main goals of this assignment are:

  • Add function definitions and calls to the compiler.

This is challenging!

It may be difficult to add functions to your compiler. It is possible that you have already made some design decisions that you would need to undo, in order to add functions. In other words, it is quite common for our implementation to fall over at this point and need some redesigning.

As such, it’s okay if you don’t completely finish this part! Put in a good effort, but don’t spend more time than you normally would on an assignment. We will have a chance to review functions before moving on to the next portion of the course.

Recommendations

Here are some suggestions for approaching this challenge:

  1. Implement the grammar, so that your parser can recognize valid programs.
  2. Ignore error-checking entirely! In particular, you can assume that there will not be any issues with function or variables names:
  • All function definitions are unique.
  • Every function call invokes a function that has been defined.
  • The programmer will not define a function named main.
  • The names of all local variables and parameters are unique within their scope.
  • The programmer will not define a parameter or local variable that has the same name as a function.
  1. Add the bare minimum to the backend that is needed to get your code to compile. At this point, it will accept hmc programs that define and call functions, but will not generate any code for function definitions or calls.
  2. Implement the backend so that it can handle functions that do not define any parameters. In other words, your emitter can entirely ignore parameter declarations and argument values.
  3. Make a plan for how to handle functions that define parameters.
  4. Document your plan in README.md. You will use this plan as part of the presentation you create for this compiler.

If you get this far and still have time left, start implementing your plan and get as far as you can!

Files

As before, continue working in your same repository. If you have been working in a group and want to work alone (or vice versa), you can combine / split repos as needed!

Reference implementation for hmc 3.0

There is a reference implementation for the previous assignment, in our GitHub organization.